import plotly.express as px
from die import Die

# 创建两个八面骰子实例
die_1 = Die()
die_2 = Die()

# 投掷骰子并将结果存储到列表中
results = []
for roll_num in range(1_000):
    result = die_1.rolling_die()+die_2.rolling_die()
    results.append(result)

# 分析结果
frequencies = []
max_result = die_1.num_sides + die_2.num_sides
poss_results = range(1,max_result+1)
for value in poss_results:
    frequency = results.count(value)
    frequencies.append(frequency)

# 对结果进行可视化处理
title = "Results of rolling two D8 1_000 times"
labels = {'x':'Result','y':'Frequency of Result'}
fig = px.bar(x=poss_results,y=frequencies,title=title,labels=labels)

# 进一步定制图像
fig.update_layout(xaxis_dtick = 1)

# 绘制图像
fig.show()
print(frequencies)